# _*_ coding:utf-8 _*_
# @Time  : 2022.10.25
# @Author: zizlee
import datetime
import requests
import pandas as pd


def read_file():
    df = pd.read_excel('xlsx/32烧碱山东.xlsx', engine='openpyxl', dtype={0: str})
    df.rename(columns={'datadate': 'datadate', 'datavalue': 'datavalue'}, inplace=True)
    # del df['厂家库存']
    df.sort_values(by='datadate', inplace=True)
    df['datadate'] = df['datadate'].apply(lambda x: datetime.datetime.strptime(x, '%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d'))
    df['datavalue'] = df['datavalue'].apply(lambda x: round(x, 2))
    df.dropna(inplace=True)
    # df = df[df['datadate'] >= '2018-03-26']
    # df = df[df['datadate'] <= '2023-05-01']
    print(df)
    return df.to_dict(orient='records')


def save_value(sheet_id, datalist):
    url = 'https://210.13.218.130:9000/v1/datalib/table/update/'
    body_data = {'dataid': sheet_id, 'row_value': datalist}
    r = requests.post(url, json=body_data, verify=False)
    print(r.json())


if __name__ == '__main__':
    # data_values = read_file()
    save_value(2691, [{'datadate': '2023-11-29', 'datavalue': 0}])
